package com.exam.qc.service.impl;

import com.exam.qc.mapper.ProductMapper;
import com.exam.qc.model.PageVo;
import com.exam.qc.model.Product;
import com.exam.qc.service.ProductService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;


@Service
@Transactional(rollbackFor = {Exception.class})
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductMapper productMapper;

    @Override
    public PageVo queryPage(String productName, Integer pageNo, Integer pageSize) {
        Integer totalCount = productMapper.selectTotalCount(productName);
        List<Product> list = productMapper.selectPageByName(productName,pageNo,pageSize);
        return new PageVo(pageNo,pageSize,totalCount,list);
    }

    @Override
    public List<Product> queryAll() {
        return productMapper.selectAllProduct();
    }

    @Override
    public Integer addProduct(Product product) {
        return productMapper.insertProduct(product);
    }
}
